
function getItem(node,info,results,result){
  if(!result){
    result = {}
    for(let k in info){
      result[k] = info[k]
    }
  }
  //指标项目
  if(node.itemName){
    //不存在子节点
    if(!node.children){
      let r = {};
      for(let k in result){
        r[k] = result[k]
      }

      let f = {};
      //检查指标项目名称，最小单位信息
      f.indicatorsName = node.itemName
      //指标项目id
      f.indicatorsId = node.itemId

      //指标实际输入值
      f.indicatorsActVal = (node.indicatorsActVal instanceof Array)? JSON.stringify(node.indicatorsActVal):node.indicatorsActVal
      //指标默认值
      f.indicatorsReferVal = node.defaultValue

      f.key = ""
      if(r.inspectName){
        f.key = r.inspectName + ";"
      }
      if(r.parentItemName){
        f.key += r.parentItemName
      }
      f.key += f.indicatorsName

      results.push(f)
    }else{
      //存在子节点,写入上级指标信息
      if(!result.parentItemName){
        result.parentItemName = ""
      }
      result.parentItemName += node.itemName + ";"
      for(let i in node.children){
        let n = node.children[i];
        getItem(n,info,results,result)
      }
    }
  }
}


function getInfo(d,project,results,info){
  if(!info){
    info = {}
    for(let k in project){
      info[k] = project[k]
    }
  }
  //项目
  if(d.project){
    //遍历子类
    for(let index in d.children){
      let item = d.children[index]
      //子类为项目
      if(item.project){
        if(info.parentInfoName){
          info.parentInfoName = ""
        }
        info.parentInfoName += d.project + ";"
        getInfo(item,project,results,info)
      }else{
        info.inspectName = d.project;
        info.inspectId = d.id;
        //指标项目
        getItem(item,info,results)
      }
    }
  }else{
    info.inspectName = d.project;
    info.inspectId = d.id;
    //指标项目
    getItem(d,info,results)
  }
}


export function getResults(data){
  let results = [];
  //父类属性
  let project = {
  }
  project.projectId = data.id;
  project.projectName = data.project;
  for(let index in data.children){
    getInfo(data.children[index],project,results)
  }
  return results
}
